<?php
set_time_limit(0);
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
require_once './Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '姓名')
            ->setCellValue('B1', '身份证号码')
            ->setCellValue('C1', '区')
            ->setCellValue('D1', '年级')
            ->setCellValue('E1', '学校（全称）')
            ->setCellValue('F1', '手机号码')
            ->setCellValue('G1', '填空题')
            ->setCellValue('H1', '单选题')
            ->setCellValue('I1', '多项选择题')
            ->setCellValue('J1', '判断题')
            ->setCellValue('K1', '总分')
;


include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}

 
$sql="SELECT * FROM `uinfo`  order by f5 desc  ";
$query =$mysqli->query($sql);
$index=2;
while ($list=$query->fetch_array()){
    
    $canAdd=true;
    if (0 == $list['f5']){
        $queryU=$mysqli->query("select * from uinfo_sim where id='".$list['id']."' limit 0,1 ");
        $getU=$queryU->fetch_assoc();
        $islock=$getU['islock'];
        if ('y' == $islock){
        }else{
            $canAdd=false;
        }
        
    }
    if ($canAdd){
        $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A'.$index, $list['name'])
        ->setCellValue('B'.$index, $list['idcard'].' ')
        ->setCellValue('C'.$index, $list['qu'])
        ->setCellValue('D'.$index, $list['nianji'])
        ->setCellValue('E'.$index, $list['school'])
        ->setCellValue('F'.$index, $list['phone'])
        ->setCellValue('G'.$index, $list['f1'])
        ->setCellValue('H'.$index, $list['f2'])
        ->setCellValue('I'.$index, $list['f3']*2)
        ->setCellValue('J'.$index, $list['f4'])
        ->setCellValue('K'.$index, $list['f5'])
        ;
        $index++;
    }
    
	    
	    
}

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('学生考试信息');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=学生考试信息-04-29.xlsx');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
